<?php
namespace app\home\controller;

use app\BaseController;
use app\home\model\Article;
use think\facade\View;

class Pd extends BaseController
{
    public function index()
    {
        $article = Article::find($_GET['page']);
        if($article == null){
            abort(404);
            return ;
        }
        $p_desc['content'] = trim(strip_tags($article['summary']));
        $p_desc['len'] = mb_strlen($p_desc['content']);

        $hot_page = Article::getByOrder('hot_order_desc', 7);
        $hot_page1 = [];
        $hot_page2 = [];
        foreach($hot_page as $index => $page){
            if($index < 2){
                array_push($hot_page1,$page);
            }else{
                array_push($hot_page2, $page);
            }
        }

        $map_next['id']  = array('GT',$_GET['page']);
        $map_prev['id']  = array('LT',$_GET['page']);
        $prev = Article::where($map_prev)->order("id desc")->find();
        $next = Article::where($map_next)->order("id desc")->find();

        $article_like = Article::order('id')->limit(6)->select();

        View::assign('article_like', $article_like);
        View::assign('pages_hot2', $hot_page2);
        View::assign('pages_hot1_1', $hot_page1[0]);
        View::assign('pages_hot1_2', $hot_page1[1]);
        View::assign('p_desc', $p_desc);
        View::assign('article', $article);
        View::assign('prev', $next);
        View::assign('next', $prev);

        return View::fetch('pd:index');
    }
}
